def getValue(exp):
    def value(exp, i):
        deque = []
        pre = 0      
        while i < len(exp) and exp[i] != ')':
            if ord(exp[i]) >= ord('0') and ord(exp[i]) <= ord('9'):
                pre = pre * 10 + int(exp[i])
                i += 1
            elif exp[i] != '(':
                addNum(deque, pre)
                deque.append(exp[i])
                i += 1
                pre = 0
            else:
                bra = value(exp, i + 1)
                pre = bra[0]
                i = bra[1] + 1
        addNum(deque, pre)
        return [getNum(deque), i]


    def addNum(deque, pre):
        if deque:
            top = deque.pop()
            if top == '+' or top == '-':
                deque.append(top)
            else:
                cur = int(deque.pop())
                pre = cur * pre if top == '*' else cur / pre
        deque.append(pre)


    def getNum(deque):
        res = 0
        add = True
        while deque:
            cur = deque.pop(0)
            if cur == '+':
                add = True
            elif cur == '-':
                add = False
            else:
                res += int(cur) if add else -int(cur)
        return res


    return value(exp, 0)[0]

